<template>
  <div>
    <van-goods-action>
      <van-goods-action-icon icon="chat-o" text="客服" color="#ee0a24" />
      <van-goods-action-icon
        icon="cart-o"
        text="购物车"
        :badge="
          this.$store.state.shoppingamount > 1
            ? this.$store.state.shoppingamount
            : ''
        "
        @click="toShopping"
      />
      <van-goods-action-icon
        icon="star"
        text="收藏"
        color="#ff5000"
        @click="shocheng"
      />
      <van-goods-action-button
        type="warning"
        text="加入购物车"
        @click="onClickButton"
      />
      <van-goods-action-button
        type="danger"
        text="立即购买"
        @click="onClickButton"
      />
    </van-goods-action>
  </div>
</template>

<script>
import API from "../../http/API";
import { Toast } from "vant";
import eventVue from "../../assets/zizhujian/index";
import { GoodsAction, GoodsActionIcon, GoodsActionButton } from "vant";
export default {
  name: "GoodsAction",
  props: ["ID"],
  components: {
    [GoodsAction.name]: GoodsAction,
    [Toast.name]: Toast,
    [GoodsActionIcon.name]: GoodsActionIcon,
    [GoodsActionButton.name]: GoodsActionButton,
  },
  data() {
    return {
      // 显示隐藏那个商品规格面板
      show: true,
      id: "",
    };
  },
  watch: {
    ID(val) {
      console.log(val);
      this.id = "";
      this.id = val;
    },
  },
  created() {
    console.log(this.ID);
  },
  methods: {
    onClickButton: function () {
      eventVue.$emit("myFun", this.show); //$emit这个方法会触发一个事件
    },
    toShopping() {
      this.$router.push("/shopping");
    },
    shocheng() {
      // 'collect/addordelete', //添加或取消收藏
      // 请求方式：post
      // 参数：
      // ①type: 0 表示收藏列表，1 表示专题列表,
      // ②valueId: 商品 I

      this.$post(API.POST_COLLECT_ADDORDELETE, {
        type: 0,
        valueId: this.id,
      }).then((res) => {
        console.log(res);
        Toast(res.errmsg);
      });

      // this.$get(API.POST_COLLECT_LIST,{
      //   type:1,

      // }).then((res) => {
      //   console.log(res)
      // })
    },
  },
};
</script>

<style>
</style>